/**
 * dashboard vuex
 * 行业模块
 */
const State = {
  cat: [],
  area: {} // 行业地域
};

// getters
const Getters = {
  cat: state => state.cat,
  area: state => state.area
};

// mutations
const Mutations = {
  reset: state => {
    const s = {
      cat: [],
      area: {} // 行业地域
    };
    Object.keys(s).forEach(key => {
      state[key] = s[key];
    });
  },
  SET_AREA: (state, area) => {
    state.area = { ...area };
  },
  SET_CAT: (state, { cat, index }) => {
    // 如果数组长度大于index
    if (state.cat.length - 1 >= index) {
      state.cat = state.cat.slice(0, index);
    }
    state.cat.push(cat);
  }
};
// actions
const Actions = {
  storeCat({ commit }, { cat, index }) {
    commit('SET_CAT', { cat, index });
  },
  storeArea({ commit }, area) {
    commit('SET_AREA', area);
  }
};

export default {
  namespaced: true,
  strict: true,
  state: State,
  getters: Getters,
  actions: Actions,
  mutations: Mutations
};
